<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
mysql_connect("$server","$s_user","$s_pass") or die ("ไม่สามารถเชื่อมต่อฐานข้อมูลได้");
mysql_select_db("$db_name") or die ("ไม่สามารถเชื่อมต่อฐานข้อมูลได้sssss");
mysql_query('SET NAMES utf8');


    function selectfrom($table)
    {
	    $sql = "SELECT * FROM $table";
		$result = mysql_query($sql);
	    if(mysql_errno() > 0)  die (mysql_error());
		return mysql_fetch_array($result);
	}
	
	 function selectuser($id)
    {
	    $sql = "SELECT A.name, lname, id_all, username, 
				password,sex, major, faculty,comment,pic,status,
				B.name as 'M_name',
				C.Name as 'f_name'
				from user A, major B, faculty C
				
				WHere
				 A.id_all = '$id'
				AND A.major= B.id
				AND A.faculty= C.ID
			
				"; 	
		$result = mysql_query($sql);
	    if(mysql_errno() > 0)  die (mysql_error());
		return mysql_fetch_array($result);
	}
	
	
	function selectstudent ($id)
	{
		$sql = "SELECT A.picture,A.sex,student_code,firstname,lastname,level,blood,address,birthday,telephone,A.status
		       ,mobile,contact_name,contact_relation,contact_mobile,firstname_EN,lastname_EN,food,address,email,grad_sch,
			   father_name,mother_name,
				B.name AS m_name , C.name,lname
				FROM students A , major B , user C
				WHERE A.major = B.id 
				AND A.advisor_id = C.id_all
				AND C.status = '2'		
				AND A.student_id ='$id'
		";
		$result = mysql_query($sql);
	    if(mysql_errno() > 0)  die (mysql_error());
		return mysql_fetch_array($result);
		
		}
	
	
	
	
	
	
	
		 function select($arr,$table,$value)
    {
	    $sql = "SELECT $arr FROM $table WHERE $value";
	    
		return mysql_query($sql);
	}
	
	

	
	
	function insert($table,$fild,$value)
    {
	    $sql = "INSERT INTO $table ($fild) VALUES ($value)";
		return mysql_query($sql);
	}
	
	
	   function update($table,$sqlupdate,$sqlwhere)
    {
		
	    $sql = "update $table set $sqlupdate  WHERE $sqlwhere";
		return mysql_query($sql);
	}

		function deletesql ($table,$wheredelete)
		{
		$sql = "DELETE FROM  $table WHERE $wheredelete";
		return mysql_query($sql);
		} 


		function ext($filename) {
		$ext = explode('.',$filename );
		$i = ( count( $ext ) - 1 );
		$extension = $ext[$i];
		return $extension;
		}




    function  db_close() 
	{
	mysql_close;
	return mysql_close;
	}
	
?>


